
//
//  UIButton+Extention.swift
//  我的微博练习
//
//  Created by zhangguo on 15/10/14.
//  Copyright © 2015年 zhangguo. All rights reserved.
//

import UIKit

extension UIButton {
    
    
    convenience init(title: String, fontSize: CGFloat = 12, color: UIColor = UIColor.darkGrayColor(), backColor: UIColor = UIColor.whiteColor()) {
        
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        backgroundColor = backColor
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
    convenience init (title: String,imageName:String,fontSize:CGFloat = 12,color:UIColor = UIColor.darkGrayColor()) {
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
    }
    //遍历构造函数
    convenience init(imageNmame:String) {
        self.init()
        
        setImage(imageNmame)
        
    }
    func setImage(imageName:String)
    {
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
    }
    
}


